package com.sdk.cachesdk.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CaffeineConfig {

    @Autowired
    private CaffeineProperties caffeineProperties;

    @Bean
    public Cache<String, Object> caffeineCache() {
        return Caffeine.newBuilder()
                .expireAfterWrite(caffeineProperties.getExpireAfterWrite(),
                                caffeineProperties.getExpireAfterWriteUnit())
                .maximumSize(caffeineProperties.getMaximumSize())
                .build();
    }
}
